clear all
set more off
set graphics off
capture log close
set maxvar 32000
 
global dates_coefplot_mobility_sf "_21580 _21581 _21582 _21583 _21584 _21585 _21586 _21587 _21588 _21589 _21590 _21591 _21592 _21593 _21594 _21595 _21596 _21597 _21598 _21599 _21600 _21601 _21602 _21603 _21604 _21605 _21606 _21607 _21608 _21609 _21610 _21611 _21612 _21613 _21614 _21615 _21616 _21617 _21618 _21619 _21620 _21621 _21622 _21623 _21624 _21625 _21626 _21627 _21628 _21629 _21630 _21631 _21632 _21633 _21634 _21635 _21636 _21637 _21638 _21639 _21640 _21641 _21642 _21643 _21644 _21645 _21646 _21647 _21648 _21649 _21650 _21651 _21652 _21653 _21654 _21655 _21656 _21657 _21658 _21659 _21660 _21661 _21662 _21663 _21664 _21665 _21666 _21667 _21668 _21669"


global other_rtgs_fxnc "msnbc_rtg cnn_rtg"
global other_rtgs_cnn "msnbc_rtg fxnc_rtg"
global other_rtgs_msnbc "fxnc_rtg cnn_rtg"

global other_ch_fxnc "msnbc cnn"
global other_ch_cnn "msnbc fxnc"
global other_ch_msnbc "fxnc cnn"


global outcomes_pick4 "qty_sumclean_prod qty_sumhand_sanit qty_sumtissues qty_sumtoil_paper qty_summasks tot_expclean_prod tot_exphand_sanit tot_exptissues tot_exptoil_paper tot_expmasks  tot_expcovid_prod tot_expgroc"

global outcomes_pick2 "sd_sf_dist_fr_home sd_sf_median_nohome_time"
global outcomes_pick3 "sfd_dist_fr_home sfd_home_dev_count sfd_median_home_time sfd_pt_work_dev sfd_ft_work_dev sfd_delivery_dev sfd_median_nohome_time sfd_median_pct_time_home l_sfd_dist_fr_home l_sfd_home_dev_count l_sfd_median_home_time l_sfd_pt_work_dev l_sfd_ft_work_dev l_sfd_delivery_dev l_sfd_median_nohome_time l_sfd_median_pct_time_home sd_sfd_dist_fr_home sd_sfd_home_dev_count sd_sfd_median_home_time sd_sfd_pt_work_dev sd_sfd_ft_work_dev sd_sfd_delivery_dev sd_sfd_median_nohome_time sd_sfd_median_pct_time_home"
global outcomes_pick1 "ratio_cases_pop ratio_deaths_pop"


use /Users/matteop/Dropbox/final_matteo/corona_virus/definitive_data/covid_final_2016_jh_mobility2019.dta, clear

* Data prep
replace fxnc=-fxnc
replace cnn=-cnn
replace msnbc=-msnbc
replace dif_fxnc_cnn=-dif_fxnc_cnn
replace dif_fxnc_msnbc=-dif_fxnc_msnbc

global full_controls1 " pop_dens_county landarea_county 	  age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"

* First stage base specification
preserve
foreach network in fxnc  {
replace `network'=-`network'
ivreghdfe sf_dist_fr_home21551 (`network'_rtg=`network') [aweight=pop], absorb(state_fips one##c.(${other_rtgs_`network'})) cluster(state_fips) first
binscatter 	`network'_rtg `network' [aweight=pop], absorb(state_fips) controls($full_controls1 ${other_rtgs_`network'}) nquantiles(19) ${general_options_fs_`network'}
graph export "analysis/data_alldates/channels_2016/paper_output_full/2019_firststage_`network'_censuscontrols1_state_fips.pdf", replace
}
restore



* safegraph *
foreach cl in state_fips {
	foreach network in fxnc {

	* Main outcomes REDUCED
			foreach y of global outcomes_pick2 {
				cap drop _est*
				eststo clear
					forvalues date= 21580/21670 {
					cap qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.( $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
			
					}
				}	
	*
	* Main outcomes OLS
			foreach y of global outcomes_pick2 {
				cap drop _est*
				eststo clear
					forvalues date= 21580/21670 {
					cap qui reghdfe `y'`date' `network'_rtg [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					}
				}
	*
	* Main outcomes IV
			foreach y of global outcomes_pick2 {
				cap drop _est*
				eststo clear
					forvalues date= 21580/21670 {
					cap qui ivreghdfe `y'`date' (`network'_rtg= `network') [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					}
				}
	*
	}
}
*				
				
